﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.ComponentModel;
using Microsoft.Phone.Shell;

namespace LiveEduWizard.Views
{
    public partial class AppointmentView : PhoneApplicationPage
    {
        public AppointmentView()
        {
            InitializeComponent();
            InitApplicationBar();

            // Set the data context of the listbox control to the sample data
            DataContext = App.ViewModel;
        }

        private void InitApplicationBar()
        {
            ApplicationBar = new ApplicationBar();
            ApplicationBar.Mode = ApplicationBarMode.Default;
            ApplicationBar.IsVisible = true;
            ApplicationBar.IsMenuEnabled = true;
            InitApplicationBarButtons();
        }

        private void InitApplicationBarButtons()
        {
            ApplicationBarIconButton backButton = new ApplicationBarIconButton(ThemeHelper.BackButtonImage);
            backButton.Text = ThemeHelper.BackButtonText;
            backButton.Click += new EventHandler(backButton_Click);
            ApplicationBar.Buttons.Add(backButton);
        }

        void backButton_Click(object sender, EventArgs e)
        {
            NavigationService.GoBack();
        }

        internal static void Show(AppointmentViewModel appointment)
        {
            App.ViewModel.ActiveAppointment = appointment;
            ((App)App.Current).RootFrame.Navigate(new Uri("/Views/AppointmentView.xaml", UriKind.Relative));
        }

        private void Related_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            if (sender is FrameworkElement && ((FrameworkElement)sender).DataContext is AppointmentViewModel)
            {
                Show(((FrameworkElement)sender).DataContext as AppointmentViewModel);
            }
        }
    }
}
